package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 检查项控制类
 * @Author makun
 * @Date 2023/9/13 15:35
 * @Version 1.0
 */
@RestController
@RequestMapping("/checkItem")
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;

    @GetMapping("/all")
    public Result getAllCheckItem(String queryString) {
        return Result.buildSuccess(checkItemService.getAll(queryString));
    }

    /**
     * 删除检查项
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteCheckItem(Integer id) {
        return checkItemService.delete(id) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 新增检查项
     * @param checkItem
     * @return
     */
    @PostMapping
    public Result addCheckItem(@RequestBody CheckItem checkItem) {
        return checkItemService.add(checkItem) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 查询检查项
     * @return
     */
    @GetMapping
    public Result find(QueryPageBean queryPageBean) {
        return Result.buildSuccess(checkItemService.findPage(queryPageBean));
    }
}
